package fplaton.ui.helper;

import fplaton.db.SQLiteJDBC;
import fplaton.ui.Course;
import java.sql.*;
import java.util.logging.*;
import javax.swing.DefaultListModel;

/**
 *
 * @author ASOT
 */
public class CourseHelpers {
    
    

    public DefaultListModel databaseToList() throws SQLException {
  
        DefaultListModel<String> item= new DefaultListModel();
        Connection connection=null;
        try {
            connection = DriverManager.getConnection("jdbc:sqlite:frontistirio.db");
        } catch (SQLException ex) {
            Logger.getLogger(Course.class.getName()).log(Level.SEVERE, null, ex);
        }
        String sql = "SELECT COURSENAME FROM COURSES";
        PreparedStatement preparedS = connection.prepareStatement(sql);
        ResultSet resultS = preparedS.executeQuery(); 
        
        while(resultS.next()) {
            String itemCourse = resultS.getString("COURSENAME");
            item.addElement(itemCourse);
        }
        return item;
    }  

    public boolean clearList(int index, DefaultListModel item) {
        if (index >= 0) {
            item.removeElement(index);
            return true;
        }
        return false;
    }

   
    
}
